package com.hckjsec.common.utils;
import com.alibaba.fastjson.JSONObject;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.trtc.v20190722.TrtcClient;
import com.tencentcloudapi.trtc.v20190722.models.EncodeParams;
import com.tencentcloudapi.trtc.v20190722.models.LayoutParams;
import com.tencentcloudapi.trtc.v20190722.models.OutputParams;
import com.tencentcloudapi.trtc.v20190722.models.StartMCUMixTranscodeRequest;
import com.tencentcloudapi.trtc.v20190722.models.StartMCUMixTranscodeResponse;
import com.tencentcloudapi.trtc.v20190722.models.StopMCUMixTranscodeRequest;
import com.tencentcloudapi.trtc.v20190722.models.StopMCUMixTranscodeResponse;

public class WxTencentCloudUtil {
    private final static String  endpoint = "trtc.tencentcloudapi.com";

    private final static String  region = "ap-beijing";

    public static String hladd(String secretId, String secretKey, String SdkAppId,String RoomId,String StreamId) {
        String msg="";
        try{
            Credential cred = new Credential(secretId, secretKey);
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint(endpoint);
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            TrtcClient client = new TrtcClient(cred, "ap-beijing", clientProfile);
            StartMCUMixTranscodeRequest req = new StartMCUMixTranscodeRequest();
            req.setSdkAppId(Long.valueOf(SdkAppId));
            req.setRoomId(Long.valueOf(RoomId));
            LayoutParams layoutParams1 = new LayoutParams();
            layoutParams1.setTemplate(1L);
            req.setLayoutParams(layoutParams1);

            OutputParams outputParams1 = new OutputParams();
            outputParams1.setStreamId(StreamId);
            outputParams1.setPureAudioStream(0L);
            req.setOutputParams(outputParams1);

            EncodeParams encodeParams1 = new EncodeParams();
            encodeParams1.setAudioSampleRate(48000L);
            encodeParams1.setAudioBitrate(64L);
            encodeParams1.setAudioChannels(2L);
            encodeParams1.setVideoFramerate(15L);
            encodeParams1.setVideoGop(3L);
            encodeParams1.setVideoWidth(1366L);
            encodeParams1.setVideoHeight(768L);
            encodeParams1.setVideoBitrate(2000L);

            req.setEncodeParams(encodeParams1);
            StartMCUMixTranscodeResponse resp = client.StartMCUMixTranscode(req);
            String requestMsg=StartMCUMixTranscodeResponse.toJsonString(resp);
            JSONObject jsonObject = JSONObject.parseObject(requestMsg);
            msg=jsonObject.getString("RequestId");
        } catch (TencentCloudSDKException e) {
            msg="";
            System.out.println(e.toString());
        }
        return msg;
    }
    public static void closehd(String secretId, String secretKey,String SdkAppId, String RoomId){
        try{
            Credential cred = new Credential(secretId, secretKey);
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint(endpoint);
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            TrtcClient client = new TrtcClient(cred, region, clientProfile);
            StopMCUMixTranscodeRequest req = new StopMCUMixTranscodeRequest();
            req.setSdkAppId(Long.valueOf(SdkAppId));
            req.setRoomId(Long.valueOf(RoomId));
            StopMCUMixTranscodeResponse resp = client.StopMCUMixTranscode(req);
        } catch (TencentCloudSDKException e) {
            System.out.println(e.toString());
        }
    }
}
